#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int t;
char s1[50],s2[50];
int d1,d2,m1,m2,yy1,yy2;
char ss[50][50]={"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November" , "December"};
bool check(int year){
    return year%4==0 && year%100!=0 || year%400==0;
}
int main(void){
    scanf("%d",&t);
    int c=1;
    while(t--){
        scanf("%s %d,%d",s1,&d1,&yy1);
        scanf("%s %d,%d",s2,&d2,&yy2);
        for(int i=0;i<12;i++){
            if(strcmp(s1,ss[i])==0){
                m1=i+1;
                break;
            }
        }
        for(int i=0;i<12;i++){
            if(strcmp(s2,ss[i])==0){
                m2=i+1;
                break;
            }
        }
        int sum=(int(yy2/4)-int(yy2/100)+int(yy2/400))-(int(yy1/4)-int(yy1/100)+int(yy1/400));
        if(check(yy1) && (m1==1 || m1==2 && d1<=29)){
            sum++;
        }
        if(check(yy2) && (m2==1 || m2==2 && d2<29)){
            sum--;
        }
        printf("Case #%d: %d\n",c++,sum);
    }
    return 0;
}